<?php

namespace App\Http\Controllers\Sms;

use App\Http\Controllers\Controller;
use Config;

class AliSmsController extends Controller
{	
	public $appkey;
	private $secret;
	
	function __construct(){
		require_once(app_path().'/Http/Library/AlidayuSms/TopSdk.php');
        $this->appkey = Config::get('zhysystem.ali_sms_key');
        $this->secret = Config::get('zhysystem.ali_sms_secret');
	}

	//发送短信（验证码）
	public function doSms($phone,$txt){
		date_default_timezone_set('Asia/Shanghai');
		$c = new \TopClient;
		$c->appkey = $this->appkey;
		$c->secretKey = $this->secret;
        $sms_type = 'SMS_27435260';
		$req = new \AlibabaAliqinFcSmsNumSendRequest;
		$req->setSmsType("normal");
		$req->setSmsFreeSignName("车漫行");
		$req->setSmsParam ( "{name:'车漫行',code:\"$txt\"}" );
		$req->setRecNum($phone);
		$req->setSmsTemplateCode($sms_type);
		$resp = $c->execute($req);
		return $resp;
	}
	
	//发送短信（信息通知）
	public function doSmsInfo($phone,$name,$fname,$fcode){
		date_default_timezone_set('Asia/Shanghai'); 
    	$c = new \TopClient;
		$c->appkey = $this->appkey;
		$c->secretKey = $this->secret;
		$sms_type = 'SMS_27435260';
		$req = new \AlibabaAliqinFcSmsNumSendRequest;
		$req->setSmsType("normal");
		$req->setSmsFreeSignName("车漫行");
		$req->setSmsParam ( "{name:\"$name\",fname:\"$fname\",fcode:\"$fcode\"}" );
		$req->setRecNum($phone);
		$req->setSmsTemplateCode($sms_type);
		$resp = $c->execute($req);
		return $resp;
	}
	
	
	//发送短信（发送密码）
	public function doSmsPasswd($phone,$passwd){
		date_default_timezone_set('Asia/Shanghai'); 
    	$c = new \TopClient;
		$c->appkey = $this->appkey;
		$c->secretKey = $this->secret;
		$sms_type = 'SMS_30265111';
		$req = new \AlibabaAliqinFcSmsNumSendRequest;
		$req->setSmsType("normal");
		$req->setSmsFreeSignName("车漫行");
		$req->setSmsParam ( "{passwd:\"$passwd\"}" );
		$req->setRecNum($phone);
		$req->setSmsTemplateCode($sms_type);
		$resp = $c->execute($req);
		return $resp;
	}
}